using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using iBeauty.BusinessObjects;

namespace iBeauty.DAL
{
	public class ProductDAO
	{
		public ProductDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Product> GetProducts()
		{
			try
			{
				List<Product> lstProducts = new List<Product>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[ProductCode],[ProductName],[GroupId],[OriginalPrice],[SalePrice],[OriginalForeignPrice],[SaleForeignPrice],[Currency],[Barcode],[Unit],[Capacity],[AccountId],[Note] FROM [Product]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Product oProduct = new Product();
					oProduct.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oProduct.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oProduct.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oProduct.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["ProductCode"] != DBNull.Value)
						oProduct.ProductCode = Convert.ToString(oDbDataReader["ProductCode"]);

					if(oDbDataReader["ProductName"] != DBNull.Value)
						oProduct.ProductName = Convert.ToString(oDbDataReader["ProductName"]);

					if(oDbDataReader["GroupId"] != DBNull.Value)
						oProduct.GroupId = Convert.ToString(oDbDataReader["GroupId"]);

					if(oDbDataReader["OriginalPrice"] != DBNull.Value)
						oProduct.OriginalPrice = Convert.ToSingle(oDbDataReader["OriginalPrice"]);

					if(oDbDataReader["SalePrice"] != DBNull.Value)
						oProduct.SalePrice = Convert.ToSingle(oDbDataReader["SalePrice"]);

					if(oDbDataReader["OriginalForeignPrice"] != DBNull.Value)
						oProduct.OriginalForeignPrice = Convert.ToSingle(oDbDataReader["OriginalForeignPrice"]);

					if(oDbDataReader["SaleForeignPrice"] != DBNull.Value)
						oProduct.SaleForeignPrice = Convert.ToSingle(oDbDataReader["SaleForeignPrice"]);

					if(oDbDataReader["Currency"] != DBNull.Value)
						oProduct.Currency = Convert.ToString(oDbDataReader["Currency"]);

					if(oDbDataReader["Barcode"] != DBNull.Value)
						oProduct.Barcode = Convert.ToString(oDbDataReader["Barcode"]);

					if(oDbDataReader["Unit"] != DBNull.Value)
						oProduct.Unit = Convert.ToString(oDbDataReader["Unit"]);

					if(oDbDataReader["Capacity"] != DBNull.Value)
						oProduct.Capacity = Convert.ToSingle(oDbDataReader["Capacity"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oProduct.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oProduct.Note = Convert.ToString(oDbDataReader["Note"]);
					lstProducts.Add(oProduct);
				}
				oDbDataReader.Close();
				return lstProducts;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Product GetProduct(string ID)
		{
			try
			{
				Product oProduct = new Product();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[ProductCode],[ProductName],[GroupId],[OriginalPrice],[SalePrice],[OriginalForeignPrice],[SaleForeignPrice],[Currency],[Barcode],[Unit],[Capacity],[AccountId],[Note] FROM [Product] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oProduct.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oProduct.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oProduct.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oProduct.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["ProductCode"] != DBNull.Value)
						oProduct.ProductCode = Convert.ToString(oDbDataReader["ProductCode"]);

					if(oDbDataReader["ProductName"] != DBNull.Value)
						oProduct.ProductName = Convert.ToString(oDbDataReader["ProductName"]);

					if(oDbDataReader["GroupId"] != DBNull.Value)
						oProduct.GroupId = Convert.ToString(oDbDataReader["GroupId"]);

					if(oDbDataReader["OriginalPrice"] != DBNull.Value)
						oProduct.OriginalPrice = Convert.ToSingle(oDbDataReader["OriginalPrice"]);

					if(oDbDataReader["SalePrice"] != DBNull.Value)
						oProduct.SalePrice = Convert.ToSingle(oDbDataReader["SalePrice"]);

					if(oDbDataReader["OriginalForeignPrice"] != DBNull.Value)
						oProduct.OriginalForeignPrice = Convert.ToSingle(oDbDataReader["OriginalForeignPrice"]);

					if(oDbDataReader["SaleForeignPrice"] != DBNull.Value)
						oProduct.SaleForeignPrice = Convert.ToSingle(oDbDataReader["SaleForeignPrice"]);

					if(oDbDataReader["Currency"] != DBNull.Value)
						oProduct.Currency = Convert.ToString(oDbDataReader["Currency"]);

					if(oDbDataReader["Barcode"] != DBNull.Value)
						oProduct.Barcode = Convert.ToString(oDbDataReader["Barcode"]);

					if(oDbDataReader["Unit"] != DBNull.Value)
						oProduct.Unit = Convert.ToString(oDbDataReader["Unit"]);

					if(oDbDataReader["Capacity"] != DBNull.Value)
						oProduct.Capacity = Convert.ToSingle(oDbDataReader["Capacity"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oProduct.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oProduct.Note = Convert.ToString(oDbDataReader["Note"]);
				}
				oDbDataReader.Close();
				return oProduct;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddProduct(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string ProductCode,string ProductName,string GroupId,Single?OriginalPrice,Single?SalePrice,Single?OriginalForeignPrice,Single?SaleForeignPrice,string Currency,string Barcode,string Unit,Single?Capacity,int?AccountId,string Note)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Product]([CreateDate],[ModifiedDate],[TimeStamp],[ProductCode],[ProductName],[GroupId],[OriginalPrice],[SalePrice],[OriginalForeignPrice],[SaleForeignPrice],[Currency],[Barcode],[Unit],[Capacity],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@ProductCode,@ProductName,@GroupId,@OriginalPrice,@SalePrice,@OriginalForeignPrice,@SaleForeignPrice,@Currency,@Barcode,@Unit,@Capacity,@AccountId,@Note)",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (GroupId!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,GroupId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,DBNull.Value));
				if (OriginalPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,OriginalPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,DBNull.Value));
				if (SalePrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,SalePrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,DBNull.Value));
				if (OriginalForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,OriginalForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,DBNull.Value));
				if (SaleForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,SaleForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,DBNull.Value));
				if (Currency!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,Currency));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,DBNull.Value));
				if (Barcode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,Barcode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,DBNull.Value));
				if (Unit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,Unit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,DBNull.Value));
				if (Capacity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,Capacity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddProduct(Product oProduct)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Product]([CreateDate],[ModifiedDate],[TimeStamp],[ProductCode],[ProductName],[GroupId],[OriginalPrice],[SalePrice],[OriginalForeignPrice],[SaleForeignPrice],[Currency],[Barcode],[Unit],[Capacity],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@ProductCode,@ProductName,@GroupId,@OriginalPrice,@SalePrice,@OriginalForeignPrice,@SaleForeignPrice,@Currency,@Barcode,@Unit,@Capacity,@AccountId,@Note)",CommandType.Text);
				if (oProduct.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oProduct.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oProduct.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oProduct.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oProduct.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oProduct.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oProduct.ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,oProduct.ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (oProduct.ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,oProduct.ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (oProduct.GroupId!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,oProduct.GroupId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,DBNull.Value));
				if (oProduct.OriginalPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,oProduct.OriginalPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,DBNull.Value));
				if (oProduct.SalePrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,oProduct.SalePrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,DBNull.Value));
				if (oProduct.OriginalForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,oProduct.OriginalForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,DBNull.Value));
				if (oProduct.SaleForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,oProduct.SaleForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,DBNull.Value));
				if (oProduct.Currency!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,oProduct.Currency));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,DBNull.Value));
				if (oProduct.Barcode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,oProduct.Barcode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,DBNull.Value));
				if (oProduct.Unit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,oProduct.Unit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,DBNull.Value));
				if (oProduct.Capacity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,oProduct.Capacity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,DBNull.Value));
				if (oProduct.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oProduct.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oProduct.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oProduct.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateProduct(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string ProductCode,string ProductName,string GroupId,Single?OriginalPrice,Single?SalePrice,Single?OriginalForeignPrice,Single?SaleForeignPrice,string Currency,string Barcode,string Unit,Single?Capacity,int?AccountId,string Note)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Product] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[ProductCode]=@ProductCode,[ProductName]=@ProductName,[GroupId]=@GroupId,[OriginalPrice]=@OriginalPrice,[SalePrice]=@SalePrice,[OriginalForeignPrice]=@OriginalForeignPrice,[SaleForeignPrice]=@SaleForeignPrice,[Currency]=@Currency,[Barcode]=@Barcode,[Unit]=@Unit,[Capacity]=@Capacity,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (GroupId!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,GroupId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,DBNull.Value));
				if (OriginalPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,OriginalPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,DBNull.Value));
				if (SalePrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,SalePrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,DBNull.Value));
				if (OriginalForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,OriginalForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,DBNull.Value));
				if (SaleForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,SaleForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,DBNull.Value));
				if (Currency!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,Currency));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,DBNull.Value));
				if (Barcode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,Barcode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,DBNull.Value));
				if (Unit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,Unit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,DBNull.Value));
				if (Capacity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,Capacity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateProduct(Product oProduct)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Product] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[ProductCode]=@ProductCode,[ProductName]=@ProductName,[GroupId]=@GroupId,[OriginalPrice]=@OriginalPrice,[SalePrice]=@SalePrice,[OriginalForeignPrice]=@OriginalForeignPrice,[SaleForeignPrice]=@SaleForeignPrice,[Currency]=@Currency,[Barcode]=@Barcode,[Unit]=@Unit,[Capacity]=@Capacity,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (oProduct.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oProduct.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oProduct.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oProduct.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oProduct.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oProduct.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oProduct.ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,oProduct.ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (oProduct.ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,oProduct.ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (oProduct.GroupId!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,oProduct.GroupId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@GroupId",DbType.String,DBNull.Value));
				if (oProduct.OriginalPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,oProduct.OriginalPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalPrice",DbType.Single,DBNull.Value));
				if (oProduct.SalePrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,oProduct.SalePrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SalePrice",DbType.Single,DBNull.Value));
				if (oProduct.OriginalForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,oProduct.OriginalForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OriginalForeignPrice",DbType.Single,DBNull.Value));
				if (oProduct.SaleForeignPrice.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,oProduct.SaleForeignPrice));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleForeignPrice",DbType.Single,DBNull.Value));
				if (oProduct.Currency!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,oProduct.Currency));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Currency",DbType.String,DBNull.Value));
				if (oProduct.Barcode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,oProduct.Barcode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Barcode",DbType.String,DBNull.Value));
				if (oProduct.Unit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,oProduct.Unit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Unit",DbType.String,DBNull.Value));
				if (oProduct.Capacity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,oProduct.Capacity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Capacity",DbType.Single,DBNull.Value));
				if (oProduct.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oProduct.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oProduct.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oProduct.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oProduct.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveProduct(Product oProduct)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Product] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oProduct.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveProduct(string ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Product] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
